package com.molichuxing.gateway.bff.user.convertor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.gateway.bff.user.entity.response.ComplaintVo;
import com.molichuxing.gateway.bff.user.entity.response.DrivingLicenseVo;
import com.molichuxing.gateway.bff.user.entity.response.EnterpriseVo;
import com.molichuxing.gateway.bff.user.entity.response.IdentityCardVo;
import com.molichuxing.gateway.bff.user.entity.response.UserVo;
import com.molichuxing.services.business.dto.response.ComplaintBizDto;
import com.molichuxing.services.business.dto.response.DrivingLicenseBizDto;
import com.molichuxing.services.business.dto.response.UserBizDto;
import com.molichuxing.services.business.dto.response.UserDetailBizDto;
import com.molichuxing.services.infrastructure.dto.response.ComplaintDto;
import com.molichuxing.services.infrastructure.dto.response.DrivingLicenseDto;
import com.molichuxing.services.infrastructure.dto.response.EnterpriseDto;
import com.molichuxing.services.infrastructure.dto.response.IdentityCardDto;
import com.molichuxing.services.infrastructure.dto.response.UserDto;

/**
 * 
 * @author liyg
 * 数据转换类
 * 2019-08-16
 *
 */
public class Convert {
	
	public static UserVo toUserVo(UserBizDto userBizDto) {
		if (userBizDto == null) {
			return null;
		}

		UserVo userVo = new UserVo();
		BeanUtils.copyProperties(userBizDto, userVo);
		userVo.setUserId(userBizDto.getId());
		userVo.setRegtime(DateUtil.formatTime(userBizDto.getRegtime()));

		return userVo;
	}
	public static UserVo toUserVo(UserDetailBizDto userDetailBizDto) {
		if (userDetailBizDto == null) {
			return null;
		}

		UserVo userVo = new UserVo();
		BeanUtils.copyProperties(userDetailBizDto, userVo);
		userVo.setUserId(userDetailBizDto.getId());
		userVo.setRegtime(DateUtil.formatTime(userDetailBizDto.getRegtime()));

		return userVo;
	}
	
	public static List<UserVo> toUserVo(List<UserBizDto> userBizDtoList) {
		if(userBizDtoList == null || userBizDtoList.isEmpty()){
			return null;
		}

		List<UserVo> beanVoList;
		beanVoList = new ArrayList<>();
		for (UserBizDto bizDto : userBizDtoList) {
			beanVoList.add(toUserVo(bizDto));
		}

		return beanVoList;
	}
	
	public static UserVo toUserVo(UserDto userDto) {
		if (userDto == null) {
			return null;
		}

		UserVo userVo = new UserVo();
		BeanUtils.copyProperties(userDto, userVo);
		userVo.setUserId(userDto.getId());
		userVo.setRegtime(DateUtil.formatTime(userDto.getRegtime()));

		return userVo;
	}
	
	public static List<UserVo> toUserVoBase(List<UserDto> userDtoList) {
		if (userDtoList == null || userDtoList.isEmpty()) {
			return null;
		}

		List<UserVo> userVoList = new ArrayList<>();
		userDtoList.forEach(dto -> {
			UserVo userVo = toUserVo(dto);
			userVoList.add(userVo);
		});

		return userVoList;
	}
	
	public static ComplaintVo toComplaintVo(ComplaintBizDto complaintBizDto) {
		if (complaintBizDto == null) {
			return null;
		}

		ComplaintVo complaintVo = new ComplaintVo();
		BeanUtils.copyProperties(complaintBizDto, complaintVo);
		complaintVo.setName(complaintBizDto.getRealName());
		complaintVo.setSubmitTime(DateUtil.formatTime(complaintBizDto.getSubmitTime()));
		complaintVo.setOperationTime(DateUtil.formatTime(complaintBizDto.getOperationTime()));

		return complaintVo;
	}
	
	public static ComplaintVo toComplaintVo(ComplaintDto complaintDto) {
		if (complaintDto == null) {
			return null;
		}

		ComplaintVo beanVo = new ComplaintVo();
		BeanUtils.copyProperties(complaintDto, beanVo);
		beanVo.setSubmitTime(DateUtil.formatTime(complaintDto.getSubmitTime()));
		beanVo.setOperationTime(DateUtil.formatTime(complaintDto.getOperationTime()));

		return beanVo;
	}
	
	public static List<ComplaintVo> toComplaintVo(List<ComplaintBizDto> complaintBizDtoList) {
		if (complaintBizDtoList == null || complaintBizDtoList.isEmpty()) {
			return null;
		}

		List<ComplaintVo> complaintVoList = new ArrayList<>();
		complaintBizDtoList.forEach(dto -> complaintVoList.add(toComplaintVo(dto)));

		 return complaintVoList;
	}
	
	public static IdentityCardVo toIdentityCardVo(IdentityCardDto identityCardDto) {
		if (identityCardDto == null) {
			return null;
		}

		IdentityCardVo cardVo = new IdentityCardVo();
		BeanUtils.copyProperties(identityCardDto, cardVo);
		cardVo.setUserId(identityCardDto.getId());
		cardVo.setBirthDate(DateUtil.formatDate(identityCardDto.getBirthDate()));
		cardVo.setBeginDate(DateUtil.formatDate(identityCardDto.getBeginDate()));
		cardVo.setEndDate(DateUtil.formatDate(identityCardDto.getEndDate()));

		return cardVo;
	}
	
	public static DrivingLicenseVo toDrivingLicenseVo(DrivingLicenseBizDto drivingLicenseBizDto) {
		if (drivingLicenseBizDto == null) {
			return null;
		}

		DrivingLicenseVo drivingLicenseVo = new DrivingLicenseVo();
		BeanUtils.copyProperties(drivingLicenseBizDto, drivingLicenseVo);
		drivingLicenseVo.setUserId(drivingLicenseBizDto.getId());
		drivingLicenseVo.setBirthDate(DateUtil.formatDate(drivingLicenseBizDto.getBirthDate()));
		drivingLicenseVo.setVerifyTime(DateUtil.formatTime(drivingLicenseBizDto.getVerifyTime()));

		return drivingLicenseVo;
	}
	
	public static DrivingLicenseVo toDrivingLicenseVo(DrivingLicenseDto drivingLicenseDto) {
		if (drivingLicenseDto == null) {
			return null;
		}

		DrivingLicenseVo drivingLicenseVo = new DrivingLicenseVo();
		BeanUtils.copyProperties(drivingLicenseDto, drivingLicenseVo);
		drivingLicenseVo.setUserId(drivingLicenseDto.getId());
		drivingLicenseVo.setBirthDate(DateUtil.formatDate(drivingLicenseDto.getBirthDate()));
		drivingLicenseVo.setVerifyTime(DateUtil.formatTime(drivingLicenseDto.getVerifyTime()));

		return drivingLicenseVo;
	}
	
	public static List<DrivingLicenseVo> toDrivingLicenseVo(List<DrivingLicenseBizDto> drivingLicenseBizDtoList) {
		if (drivingLicenseBizDtoList == null || drivingLicenseBizDtoList.isEmpty()) {
			return null;
		}

		List<DrivingLicenseVo> drivingLicenseVoList = new ArrayList<>();
		drivingLicenseBizDtoList.forEach(dto -> drivingLicenseVoList.add(toDrivingLicenseVo(dto)));

		return drivingLicenseVoList;
	}
	
	public static EnterpriseVo toEnterpriseVo(EnterpriseDto dto) {
		if (dto == null) {
			return null;
		}
		EnterpriseVo vo = new EnterpriseVo();
		BeanUtils.copyProperties(dto, vo);
		return vo;
	}
	
	public static List<EnterpriseVo> toEnterpriseVo(List<EnterpriseDto> dtoList) {
		if (dtoList == null || dtoList.isEmpty()) {
			return null;
		}

		List<EnterpriseVo> voList = new ArrayList<>();
		dtoList.forEach(dto -> voList.add(toEnterpriseVo(dto)));
		return voList;
	}
}
